package Lee_code;

public class Lee_122_2 {
    public int maxProfit(int[] prices) {
        int len = prices.length;
        //dp[i][0]是持有股票, dp[i][1]是不持有股票
        int[][] dp = new int[len][2];
        dp[0][0] = -prices[0];
        dp[0][1] = 0;
        for(int i=1; i<len; i++)
        {
            dp[i][0] = Math.max(dp[i-1][0], -prices[i] + prices[i-1] + dp[i-1][0]);
            dp[i][1] = Math.max(prices[i] + dp[i-1][0], dp[i-1][1]);
        }

        return dp[len-1][1];
    }
}
